package com.kpx.app.wigdet;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.kpx.app.R;

/**
 * 一个button的警告Dialog
 *
 * @author
 */
public class DialogSingleButton extends BaseDialog implements View.OnClickListener {

    private OnButtonClickListener onbuttonClick;
    private TextView tvTitle;
    private Button btnPositive;

    public DialogSingleButton(Context context) {
        super(context);
        setContent();
    }

    public DialogSingleButton(Context context, String title, String btnText, OnButtonClickListener listener) {
        super(context);
        setContent();
        setTitle(title);
        setButtonText(btnText);
        setOnButtonClickListener(listener);
    }

    public DialogSingleButton(Context context, String title) {
        super(context);
        setTitle(title);
        setContent();
    }

    public void setTitle(String title) {
        tvTitle.setText(title);
    }

    public void setButtonText(String text) {
        btnPositive.setText(text);
    }

    private void setContent() {
        setContentView(R.layout.single_button_alert_dialog_layout);
        tvTitle = (TextView) findViewById(R.id.title);
        btnPositive = (Button) findViewById(R.id.btnPositive);

        btnPositive.setOnClickListener(this);
    }

    /**
     * 确定
     */
    public void setOnButtonClickListener(OnButtonClickListener listener) {
        this.onbuttonClick = listener;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnPositive:
                if (onbuttonClick != null)
                    onbuttonClick.onButtonClick();
                break;
        }
    }

    /**
     * 确定监听器
     */
    public interface OnButtonClickListener {
        void onButtonClick(); // 点击确定按钮
    }

}
